package com.hxgis.oc.cma.util;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.*;

@Slf4j
public class CmaRequest {
    public static List<JSONObject> queryJsonData(Map<String, Object> requestParams,String InterfaceId) {
        String url = CmaUrlGenerator.generateJsonUrl(requestParams,InterfaceId);
        try
        {
            String resultStr = HttpUtil.get(url);
            JSONObject resObject = JSONUtil.parseObj(resultStr);
            Integer returnCode = resObject.getInt("returnCode");
            if (returnCode == 0) {
                JSONArray ds = resObject.getJSONArray("DS");
                return ds.toList(JSONObject.class);
            } else {
                log.info("{} -> {} 接口返回状态码：{}，返回信息：{}", InterfaceId, returnCode, resObject.getStr("returnMessage"));
            }
        }
        catch(Exception ignored){}

        return Collections.emptyList();
    }

}
